package cn.kgc.airvue.service.impl;

import cn.kgc.airvue.dao.AirqualityindexMapper;
import cn.kgc.airvue.pojo.Airqualityindex;
import cn.kgc.airvue.pojo.AirqualityindexExample;
import cn.kgc.airvue.service.AirQualitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AirQualitServiceImpl implements AirQualitService {
    @Resource
    AirqualityindexMapper airqualityindexMapper;
    @Override
    public PageInfo<Airqualityindex> sele(Integer pageNum, Integer districtid) {
        PageHelper.startPage(pageNum,3);
        List<Airqualityindex> airqualityindices;
    if(districtid!=0){
        AirqualityindexExample example=new AirqualityindexExample();
        AirqualityindexExample.Criteria criteria = example.createCriteria();
        criteria.andDistrictidEqualTo(districtid);
         airqualityindices = airqualityindexMapper.selectByExample(example);
    }else{
        airqualityindices = airqualityindexMapper.selectByExample(null);

    }
        PageInfo<Airqualityindex> pageInfo=new PageInfo<>(airqualityindices);
        return pageInfo;
    }

    @Override
    public Integer add(Airqualityindex airqualityindex) {
        return airqualityindexMapper.insert(airqualityindex);
    }
}
